package com.colin.app.activity.method;

import android.Manifest;
import android.os.Environment;

import com.colin.app.app.BaseModelImpl;
import com.colin.app.bean.DemoBean;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Colin on 2017/2/7.
 */

public class MethodModelImpl extends BaseModelImpl implements MethodContract.MethodModel {
    private DemoBean demoBean;
    private File mImageFile;//选择图片拍照保存之后的文件名
    public MethodModelImpl(DemoBean demoBean) {
        this.demoBean = demoBean;
    }

    @Override
    public String getTitle() {
        String title = "Title";
        if (null != demoBean) {
            title = demoBean.getTitle();
        }
        return title;
    }

    @Override
    public List<String> getPermissionList() {
        List<String> permissionList = new ArrayList<>();
        permissionList.add(Manifest.permission.CAMERA);
        permissionList.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
        permissionList.add(Manifest.permission.READ_EXTERNAL_STORAGE);
        return permissionList;
    }

    @Override
    public boolean photoFileCreateSucceed() {
        boolean createSucceed =false ;
        mImageFile = new File(Environment.getExternalStorageDirectory(), String.valueOf(System.currentTimeMillis()) + ".png");
        try {
            mImageFile.createNewFile();
            createSucceed = mImageFile.exists();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return createSucceed;
    }

    @Override
    public File getPhotoFile() {
        return mImageFile;
    }

}
